package com.woniuxy.secondkill.consumer;

import com.rabbitmq.client.Channel;
import com.woniuxy.secondkill.configuration.RabbitMQConfiguration;
import com.woniuxy.secondkill.utils.WebSocketUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Author zhangyong
 * @Date 2021/8/13 0013下午 2:23
 */
@Component
public class DeadConsumer {

    @RabbitListener(queues = RabbitMQConfiguration.DEAD_QUEUE)
    public void consume(Message message, Channel channel) throws Exception {
        //秒杀失败的消息   通过消息推送，将结果返回给浏览器    websocket

        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        //1.拿账号
        String account = new String(message.getBody());
        //调用工具类，发送消息
        WebSocketUtil.send(account,"很遗憾，下次趁早");


    }
}
